package com.lei.demo.service;

import java.util.Random;

import javax.transaction.Transactional;

import org.apache.commons.lang.math.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lei.demo.dao.UsersDAO;
import com.lei.demo.entity.Users;


@Service
public class UserService {
	@Autowired
	private UsersDAO userDao;
	

	public int userCount(){
		return userDao.getAllUser().size();
	}

	public UsersDAO getUserDao() {
		return userDao;
	}

	public void setUserDao(UsersDAO userDao) {
		this.userDao = userDao;
	}

	@Transactional
	public void updateUser() {
		Users users1 = userDao.findById(1);
		users1.setNice_name("admin11"+RandomUtils.nextInt(10000));
		userDao.update(users1);
		
		Users user2 = new Users();
		user2.setNice_name("admin");
		userDao.save(user2);
	}
}
